/**
 * Moondance UML modeling tool
 * 
 * This program is free software; you can redistribute it and
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package ro.pub.cs.se.moondance.model;

public class Transition extends ModelElement {
	private static final long serialVersionUID = 7373023046496184280L;
	private String name;
	private String visibility;
	private String event = "none";
	private String action = "none";
	private String guard = "none";
	private UMLState source, target;
	private boolean isConnected;

	public Transition(String visibility, String name, UMLState source,
			UMLState target) {
		this.visibility = visibility;
		this.name = name;

		this.source = source;
		this.target = target;
		reconnect();
	}

	public void addGuard(String guard) {
		this.guard = guard;
	}

	public String getGuard() {
		return guard;
	}

	public void addEvent(String event) {
		this.event = event;
	}

	public String getEvent() {
		return event;
	}

	public void addAction(String action) {
		this.action = action;
	}

	public String getAction() {
		return action;
	}

	// eventul va fi inclus in ghilimele
	// actiunea intre /
	// conditia intre paranteze
	public String getLabelText() {
		String labelText = "";
		labelText += name + " ";
		if (!action.equals("none"))
			labelText += "/" + action + "/";
		if (!guard.equals("none"))
			labelText += "[" + guard + "]";
		if (!event.equals("none"))
			labelText += "\"" + action + "\"";
		return labelText;
	}

	/**
	 * Reconnect this association. The association will reconnect with the UML
	 * it was previously attached to.
	 */
	public void reconnect() {
		if (!isConnected) {
			isConnected = true;
		}
	}

	/**
	 * Disconnect this connection from the UML it is attached to.
	 */
	public void disconnect() {
		if (isConnected) {
			isConnected = false;
		}
	}

	/**
	 * Reconnect to a different source and/or target shape. The connection will
	 * disconnect from its current attachments and reconnect to the new source
	 * and target.
	 * 
	 * @param newSource
	 *            a new source endpoint for this connection (non null)
	 * @param newTarget
	 *            a new target endpoint for this connection (non null)
	 * @throws IllegalArgumentException
	 *             if any of the paramers are null or newSource == newTarget
	 */

	public void reconnect(UMLState newSource, UMLState newTarget) {
		disconnect();
		this.source = newSource;
		this.target = newTarget;
		reconnect();
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setVisibility(String visibility) {
		this.visibility = visibility;
	}

	public String getName() {
		return name;
	}

	public String getVisibility() {
		return visibility;
	}

	public UMLState getSource() {
		return source;
	}

	public UMLState getTarget() {
		return target;
	}

}
